from etgui import *
from PageLayout import *
from FontBox import *
from AllModelDictEditors import TextPropertiesModelDictEditor,DocSymbolModelDictEditor

def MakePageTools(model):
	path="GUI.Tools"+'.'
 
	enablePath=(path+"UseErrorLogFile")
	enableItem1=Form(
		items=[
			"Log File",PotGuiFileSelector(path+"ErrorLogFile",gTextFieldLen,"Log File")
		]
	)
	FieldEnabler(model,enablePath,
		items=[
			enableItem1
		]
	)
 
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("File Modification",
			PotGuiToggleButton(path+"MakeBackup","Make Backups"),
			Form(
				items=[
					"New Files Template Directory",PotGuiDirSelector(path+"TemplateDir",gTextFieldLen),
					"Undo Levels",PotGuiIntField(path+"UndoLevel",IntField(-1,25,0,100))
				]
			)
		),
		MakeBorderedSectionLayout("History",
			Form(
				items=[
					"Max. No. of History Menu Entries",PotGuiIntField(path+"HistorySize",IntField(-1,25,0,100))
				]
			)
		),
		MakeBorderedSectionLayout("Logging",
			PotGuiToggleButton(path+"PopupErrorLog","Open Log Window on Output"),
			PotGuiToggleButton(enablePath,"Use Log File"),
			enableItem1
		),
		MakeBorderedSectionLayout("Clipboard",
			Form(
				items=[
					"Column Separator",
					PotGuiTextField(
						path+"ClipBoardColumnSeparator",
						TextField(-1,3)
					),
					"Line Separator",
					PotGuiTextField(
						path+"ClipBoardLineSeparator",
						TextField(-1,3)
					)
				]
			)#,
#			PotGuiToggleButton(path+"CopyUnsorted","Copy Unsorted (Fast Copy)")
		)
	)

class AdvancedDialog(SubDialog):
	def MakeDialogInner(self,model):
		path="GUI.Tools.ED"+'.'
		lineSeparatorStyle=PotGuiPopupButton(path+"LineSeparatorStyle")
		lineSeparatorStyle.AddItem("As Is",0)
		lineSeparatorStyle.AddItem("Unix",1)
		lineSeparatorStyle.AddItem("Dos",2)
		lineSeparatorStyle.AddItem("Mac",3)
		errorMessages=PotGuiOneOf(path+"ForErrorMessages",eVObjHExpand,gPoint0,Point(1,0))
		errorMessages.AddItem("Reusable","AnyReusable")
		errorMessages.AddItem("Showing File","Showing")
		errorMessages.AddItem("Last Started Make","Maker")
		editorRequests=PotGuiOneOf(path+"ForEditorRequests",eVObjHExpand,gPoint0,Point(1,0))
		editorRequests.AddItem("Reusable","AnyReusable")
		editorRequests.AddItem("Showing File","Showing")
 
		return MakePageLayout(eVObjHExpand|eVObjVCenter,
			MakeBorderedSectionLayout("Line Separator Style",
				lineSeparatorStyle
			),
			MakeBorderedSectionLayout("Source Editor for Error Messages",
				errorMessages
			),
			MakeBorderedSectionLayout("Source Editor for Editor Requests",
				editorRequests
			)
		)	


class TextPropertiesDialog(SubDialog):
	path="????" # override in subclass
	def BeforeShow(self):
		self.editor.DoEditBegin()
	def AfterShow(self):
		self.editor.DoEditEnd()
	def MakeDialogInner(self,model):
		self.editor=TextPropertiesModelDictEditor(model,self.path,"Text Properties")
		return MakePageLayout(eVObjHExpand|eVObjVExpand,
			MakeModelDictEditorLayout(self.editor,0)
		)
class EDTextPropertiesDialog(TextPropertiesDialog):
	path="GUI.Tools.ED.Symbol"

def MakePageED(model):
	path="GUI.Tools.ED"+'.'
 
	enablePath=path+"Current"
	enableItem1=MakeBorderedSectionLayout("Alignment and Visibility",
		Form(
			items=[
				"Editor Width [chars]",PotGuiIntField(path+"TextViewWidth",IntField(-1,160,0,1024))
			]
		),
		PotGuiToggleButton(path+"FillIndentationWithTabs","Fill Indent with Tabs"),
		Form(
			items=[
				"Indent Size [chars]",PotGuiIntField(path+"IndentationSize",IntField(-1,4,0,50))
			]
		),
		PotGuiToggleButton(path+"AutoIndentation","Automatically Indent Input Text"),
		PotGuiToggleButton(path+"ShowInvisibles","Show Nonprinting Characters")
	)
	enableItem2=MakeBorderedSectionLayout("Text Highlighting",
		Form(
			items=[
				"Text Properties for Symbol and Keyword Highlighting",MakeFieldLayout(
					ActionButton("Choose...",action=EDTextPropertiesDialog(EditPotGuiModel(model),"Text Properties"))
				)
			]
		),
		PotGuiToggleButton(path+"KeywordHighlighting","Support for Keyword Highlighting")
	)
	enableItem3=AdvancedButton(AdvancedDialog(EditPotGuiModel(model),title="Advanced"))
 
	class EDFieldEnabler(FieldEnabler):
		def IsEnabled(self,value):
			return value=="SNiFF+"
 
	EDFieldEnabler(model,enablePath,
		items=[
			enableItem1,
			enableItem2,
			enableItem3
		]
	)
 
	whichEditor=PotGuiPopupButton(enablePath)
	whichEditor.AddItem("SNiFF+","SNiFF+")
	itemsList=EditorIntegrationNames()
	for v in itemsList:
		whichEditor.AddItem(v,v)   # (display, model)
 
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("Settings",
			Filler(gPoint0),
			Form(
				items=[
					"Current Editor",MakeFieldLayout(whichEditor)
				]
			)
		),
		enableItem1,
		enableItem2,
		enableItem3
	)

def MakePageRE(model):
	path="GUI.Tools.RE"+'.'
 
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("General Settings",
			Form(
				items=[
					"Filter File",PotGuiFileSelector(path+"FilterFile",gTextFieldLen,"Filter File")
				]
			),
			PotGuiToggleButton(path+"UseCache","Create Index"),
#            Form(
#                items=[
#                    "Maximum Number of Cache Files",PotGuiIntField(path+"CacheSize",IntField(-1,20,0,1000))
#                ]
#            )
		)
	)

def MakePageCR(model):
	path="GUI.Tools.CR"+'.'

	enablePath=(path+"UseDatabase")
	enableItem1=Form(
		items=[
			"Data Cache Size (kB)",PotGuiIntField(path+"DataCacheSize",IntField(-1,1000,0,10000)),
			"Index Cache Size (kB)",PotGuiIntField(path+"IndexCacheSize",IntField(-1,3000,0,10000))
		]
	)
	enableItem2=Form(
		items=[
			"Max. No. of Cached Files",PotGuiIntField(path+"CacheSize",IntField(-1,50,0,1000)),
		]
	)

	FieldEnabler(model,enablePath,
		items=[
			enableItem1
		]
	)
	InverseFieldEnabler(model,enablePath,
		items=[
			enableItem2
		]
	)
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("General Settings",
			enableItem2,
			PotGuiToggleButton(path+"UseClass","Ignore Macro with Same Name")
		),
		MakeBorderedSectionLayout("Database Settings",
			PotGuiToggleButton(path+"UseDatabase","Use Database"),
			enableItem1
		)
	)
class DETextPropertiesDialog(TextPropertiesDialog):
	path="GUI.Tools.DE.HTML"
 
def MakePageDE(model):
	path="GUI.Tools.DE"+'.'
	textprops=DETextPropertiesDialog(EditPotGuiModel(model),"HTML Tags Text Properties")
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("Alignment",
			Form(
				items=[
					"Editor Width [chars]",PotGuiIntField(path+"TextViewWidth",IntField(-1,160,0,1024))
				]
			),
		),
		MakeBorderedSectionLayout("Text Highlighting",
			Form(
				items=[
					"Text Properties for HTML Tags",MakeFieldLayout(ActionButton("Choose...",action=textprops))
				]
			),
			Filler(gPoint0)
		),
		MakeBorderedSectionLayout("Document Creation",
			Form(
				items=[
					"Documentation Template Directory",PotGuiDirSelector(path+"TemplateDir",gTextFieldLen)
				]
			),
			HBox(
				align=eVObjHExpand,
				items=[
					PotGuiToggleButton(path+"SortAlphabetic","Sort Symbols Alphabetically"),
					PotGuiToggleButton(path+"ReadOnly","Use Read-Only Mode")
				]
			)
		),
		MakeBorderedSectionLayout("Documentable Symbol",
			MakeModelDictEditorLayout(DocSymbolModelDictEditor(model,path+"Item","Documentable Symbol"),0)
		)
	)

def MakePageSH(model):
	path="GUI.Tools.SH"+'.'
 
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("General Settings",
			Form(
				items=[
					"Local Shell Executable",PotGuiFileSelector(path+"LocalExecutable",gTextFieldLen,"Executable"),
					"Local Executable for Remote Shell",PotGuiFileSelector(path+"RemoteExecutable",gTextFieldLen,"Executable")
				]
			)#,
			#PotGuiToggleButton(path+"Popup","Popup on Output"),
		)#,
#		MakeBorderedSectionLayout("Font",
#			FontBox(model,path+"Font",None,1,1)
#		)
	)

def MakePageWE(model):
	path="GUI.Tools.WE"+'.'
 
	return MakePageLayout(eVObjHExpand|eVObjVCenter,
		MakeBorderedSectionLayout("General Settings",
			Form(
				items=[
					"Working Environment Config. Directory",PotGuiDirSelector(path+"WorkingEnvDir",gTextFieldLen),
					"Default Working Environment",PotTextField(path+"DefaultWorkingEnv"),
				]
			)
		),
		MakeBorderedSectionLayout("Working Environment Root for Absolute Projects",
			Form(
				items=[
					"Directory",PotGuiDirSelector(path+"FakeWorkingEnvDir",gTextFieldLen)
				]
			)
		)
	)
 
